const queuedObservers=new Set();
const observe=(...fn)=>{
    for(let f of fn){
        queuedObservers.add(f);
    }
}
const observable=obj=>new Proxy(obj,{set});
function set(target,key,value,receiver){
    const result=Reflect.set(target,key,value,receiver);
    queuedObservers.forEach(observer=>observer());
    return result;
}
//被观察对象
const person = observable({
    name: '张三',
    age: 20
});
//数据变化引起观察者进行变化
//观察者
function print() {
console.log(`${person.name}, ${person.age}`)
}
function print2(){
    console.log('数据变化了')
}
observe(print,print2);
person.name = '王l';